<?php
//字符集
header("content-type:text/html;charset=utf-8;");

//连接增删改查数据库
include './login_CRUD.php';

//连接mysql
$coon = connectDB('127.0.0.1','root','qq553408','test2106');


//通过POST获取账号密码
$username = $_POST["username"];
$password = $_POST["password"];

//cookie过期时间
$outtime = time()+60*60*24;

// //查询数据账号密码是否正确
$sql = "SELECT *FROM login WHERE `username` ='$username' AND `password` = '$password'"; 
$res = mysqli_query($coon,$sql);

// //测试数据库是否连接成功
if(!$coon){
    //连接失败直接打出GG
    die('error for mysql: ' . mysqli_error($coon));
}
// //连接成功
else{
    //比较数据库的账号密码
    $row = mysqli_fetch_assoc($res);
    if ($row && $username!=""&&$password!="" ) {
         //查询账号的nickname
         $sqli = "SELECT *FROM login WHERE `username` ='$username' AND `password` = '$password'"; 

         $resi = mysqli_query($coon,$sqli);
         $nick = mysqli_fetch_array($resi);
         $nickname = $nick['nickname'];

         $resiuser = mysqli_query($coon,$sqli);
         $user = mysqli_fetch_array($resiuser);
         $username= $user['username'];

         $resifaces = mysqli_query($coon,$sqli);
         $face = mysqli_fetch_array($resifaces);
         $faces= $face['faces'];
         //设置过期时间
         setcookie("login",1,$outtime,"/QQLB/src/pages");
         setcookie("username",$username,$outtime,"/QQLB/src/pages");
         setcookie("faces",$faces,$outtime,"/QQLB/src/pages");
         setcookie("nickname","$nickname",$outtime,"/QQLB/src/pages");
         //弹到主页
         header('location: ../pages/QQread-home.html');
    } else {
        //用cookie告诉登陆界面账号密码错误
        setcookie("repeat",1,$outtime,"/QQLB/src/pages");
       //账号密码错误直接弹回登陆界面
       header('location: ../pages/login.html');
    }
};

?>